Skip to content

C#: Favor DLLs with most recent .NET Core target framework when resolving dependencies in standalone#14045

Merged
hvitved merged 1 commit intogithub:mainfrom
hvitved:csharp/standalone-resolve-target-framework
Aug 24, 2023
Merged

C#: Favor DLLs with most recent .NET Core target framework when resolving dependencies in standalone#14045
hvitved merged 1 commit intogithub:mainfrom
hvitved:csharp/standalone-resolve-target-framework

Conversation

@hvitved
Copy link
Copy Markdown
Contributor

@hvitved hvitved commented Aug 24, 2023

Nuget packages often contain multiple DLLs that target different .NET frameworks. With this PR, the standalone extractor will always choose the DLL that targets the most recent .NET Core version.

@hvitved hvitved force-pushed the csharp/standalone-resolve-target-framework branch from e11d589 to a0cf467 Compare August 24, 2023 09:07
@github-actions github-actions Bot removed the Ruby label Aug 24, 2023
@hvitved hvitved force-pushed the csharp/standalone-resolve-target-framework branch from a0cf467 to 554a2c2 Compare August 24, 2023 09:42
@hvitved hvitved marked this pull request as ready for review August 24, 2023 09:53
@hvitved hvitved requested a review from a team as a code owner August 24, 2023 09:53
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Aug 24, 2023
Copy link
Copy Markdown
Contributor

@tamasvajk tamasvajk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me. I've added some questions.


var name = reader.GetString(reader.GetTypeReference((TypeReferenceHandle)mHandle).Name);

if (name is "TargetFrameworkAttribute")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this pattern matching equivalent to name == "TargetFrameworkAttribute"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

if (
decoded.FixedArguments.Length > 0 &&
decoded.FixedArguments[0].Value is string value &&
NetCoreAppRegex().Match(value).Groups.TryGetValue("version", out var match))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This NetCoreAppRegex() call is inside a foreach. I'm not sure if there's a performance hit calling this multiple times.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think not, since the regex is RegexOptions.Compiled?


if (name is "TargetFrameworkAttribute")
{
var decoded = attrHandle.DecodeValue(new DummyAttributeDecoder());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this DecodeValue call be wrapped in a try-catch? Can the DummyAttributeDecoder throw NotImplementedExceptions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would actually like to be made aware if any of the NotImplementedExceptions are thrown.

Copy link
Copy Markdown
Contributor

@michaelnebel michaelnebel Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would be good to know if this exception is thrown, but it seems a bit harsh to propagate the exception.
Maybe it is worth logging it as debug or information?

@hvitved hvitved merged commit 763216b into github:main Aug 24, 2023
@hvitved hvitved deleted the csharp/standalone-resolve-target-framework branch August 24, 2023 18:56
Copy link
Copy Markdown
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I am late to the party! Very nice @hvitved !

using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Reflection.Metadata;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Horrible nitpick: Format Usings 😄 (I will show myself out)


if (name is "TargetFrameworkAttribute")
{
var decoded = attrHandle.DecodeValue(new DummyAttributeDecoder());
Copy link
Copy Markdown
Contributor

@michaelnebel michaelnebel Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would be good to know if this exception is thrown, but it seems a bit harsh to propagate the exception.
Maybe it is worth logging it as debug or information?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C# no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants